using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace Nirvana.HTN
{
    public abstract class HTN_Task
    {
        protected HTNTaskStatus status = HTNTaskStatus.Ready;
        private List<HTN_PreCondition> _preConditions = new List<HTN_PreCondition>();

        public void AddPreCondition(HTN_PreCondition preCondition)
        {
            if (preCondition != null && !_preConditions.Contains(preCondition))
            {
                _preConditions.Add(preCondition);
            }
        }

        public void RemovePreCondition(HTN_PreCondition preCondition)
        {
            if (_preConditions.Contains(preCondition))
            {
                _preConditions.Remove(preCondition);
            }
        }
        
        public abstract HTNTaskStatus Execute();

        public bool CheckPreCondition()
        {
            return _preConditions.All(preCondition => preCondition.Check());
        }
    }
}